package com.itheima.test.TCP.threehandshake;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Client {
    public static void main(String[] args) throws IOException {
        //创建Socket对象
        Socket socket = new Socket("127.0.0.1",1000);
        //写数据
        OutputStream out = socket.getOutputStream();
        out.write("我是黑马程序员".getBytes());
        //写结束标记
        socket.shutdownOutput();
        //读数据,为读取中文,字节流->转换流->字符缓冲流
        InputStream is = socket.getInputStream();//字节流
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");//转换流
        BufferedReader br = new BufferedReader(isr);//字符缓冲流
        String s;
        while((s = br.readLine())!=null){
            System.out.println(s);
        }
        //释放资源
        is.close();
        isr.close();
        out.close();
        br.close();
        socket.close();
    }
}
